


#ifndef PF_SETTINGS_H
#define PF_SETTINGS_H

#include <QHash>
#include <QSettings>
#include "lx_Export.h"

#define PF_SETTINGS PF_Settings::instance()

/**
 * This class can store and reload settings from a 
 * configuration file or the windoze registry.
 * Please note that the Qt default implementation doesn't
 * work as one would expect. That's why this class overwrites
 * most of the default behaviour.
 * 
 */
class LX_EXPORT PF_Settings {
public:
    PF_Settings();

public:
    /**
     * @return Instance to the unique settings object.
     */
    static PF_Settings* instance() {
        if (uniqueInstance==NULL) {
            uniqueInstance = new PF_Settings();
        }
        return uniqueInstance;
    }

    /**
     * Initialize the system.
     *
     * @param companyKey Company Key
     * @param appKey Application key
     */
    void init(const QString& companyKey, const QString& appKey);

    void beginGroup(const QString& group);
    void endGroup();

    bool writeEntry(const QString& key, int value);
    bool writeEntry(const QString& key, double value);
    bool writeEntry(const QString& key, const QVariant& value);
    bool writeEntry(const QString& key, const QString& value);
    QString readEntry(const QString& key,
                        const QString& def = QString::null,
                        bool* ok = 0);
    QByteArray readByteArrayEntry(const QString& key,
                        const QString& def = QString::null,
                        bool* ok = 0);
    int readNumEntry(const QString& key, int def=0, bool* ok=0);
	

public:
    ~PF_Settings();

private:
        QVariant readEntryCache(const QString& key);
        void addToCache(const QString& key, const QVariant& value);

protected:
    static PF_Settings* uniqueInstance;

    QHash<QString, QVariant*> cache;
    QString companyKey;
    QString appKey;
    QString group;
    bool initialized;
};

#endif

